package com.crazyauntzhang.easyshopbackend.service;

import com.crazyauntzhang.easyshopbackend.dao.SupplierDao;
import com.crazyauntzhang.easyshopbackend.domain.Supplier;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SupplierService {

	private final SupplierDao supplierDao;

	@Autowired
	public SupplierService(SupplierDao supplierDao) {
		this.supplierDao = supplierDao;
	}

	public Supplier findSupplierById(String supplierID) {
		return supplierDao.selectSupplierById(supplierID);
	}

	public List<Supplier> findSupplierByName(String supplierName) {
		return supplierDao.selectSupplierByName(supplierName);
	}

	public Supplier findMainSupplier(String itemBarcode) {
		return supplierDao.selectMainSupplier(itemBarcode);
	}

	public void addSupplier(String supplierID, String supplierName, String address, String tel) {
		supplierDao.insertSupplier(supplierID, supplierName, address, tel);
	}

	public List<Supplier> findAllSuppliers() {
		return supplierDao.selectAllSuppliers();
	}

	public void changeSupplier(String supplierID, String newSupplierID, String supplierName, String address, String tel) {
		supplierDao.updateSupplier(supplierID, newSupplierID, supplierName, address, tel);
	}

	public void deleteSupplier(String supplierID) {
		supplierDao.deleteSupplier(supplierID);
	}

}
